﻿@inherits DbLogViewerPage
@page "/admin/dblog"

@attribute [Authorize(Policies.IsAdmin)]
@layout AdminLayout

<TopSection>
    <Breadcrumbs>
        <Breadcrumb Link="/admin" Title=@L["BreadCrumbadmin"] />
        <Breadcrumb Title=@L["BreadCrumbadmindblog"] />
    </Breadcrumbs>
</TopSection>

<h1>Db Log Viewer</h1>
<p>
    Paginated viewing and fetching of system logs from the database.
</p>

@if (dbLogItems == null)
{
    <LoadingBackground ShowLogoBox="true">
        <label>@L["Loading"]</label>
    </LoadingBackground>
}
else
{
    <div class="row" style="margin-left: 0;">
        <RefreshTimer ElapsedEvent="@(async (_, __) => await LoadData(DebugLevel))" />
    </div>
    <MatSelectValue Value="DebugLevel" Items="@DebugLevels"
                    ValueSelector=@(i => i)
                    ValueChanged="(string i) => LoadData(i)">
    </MatSelectValue>
    <MatTable Items="@dbLogItems" Class="mat-elevation-z5" Striped="true" PageSize="@pageSize" ShowPaging="false">
        <MatTableHeader>
            <th>Timestamp</th>
            <th>Logging Level</th>
            <th>Log Message</th>
            <th>Exception</th>
            <th>Recorded Properties</th>
        </MatTableHeader>
        <MatTableRow>
            <td><span style="font-size:small">@context.TimeStamp.ToString()</span></td>
            <td><span style="font-size:small">@context.Level</span></td>
            <td><span style="font-size:small">@context.Message</span></td>
            <td><span style="font-size:small">@context.Exception?.ToString()</span></td>
            <td>
                @if (context.LogProperties?.Any() ?? false)
                    {
                    <ul>
                        @foreach (var propertyPair in context.LogProperties)
                            {
                            <li style="font-size:small">@($"{propertyPair.Key}:  {propertyPair.Value}")</li>
                            }
                    </ul>
                    }
            </td>
        </MatTableRow>
    </MatTable>
    <MatPaginator PageSize="@pageSize" Page="@(async e => await OnPage(e.PageIndex, e.PageSize))" Length="@totalItemsCount" Style="background: transparent"></MatPaginator>
}

@code {
}
